package clientcore;

import clientresponse.ResponseFromServer;
import java.util.HashMap;

public class ResponseFromServerTable {
    private static HashMap<Short, Class> responseTable = null;

    public ResponseFromServerTable() {

    }

    public static void init(AndroidMain ac) {
        responseTable = new HashMap<Short, Class>();
        try {
            responseTable.put(Constants.SMSG_AUTH_RESPONSE, Class.forName("clientresponse." + "ResponseLogin"));
            responseTable.put(Constants.SMSG_BOARD_QUESTION, Class.forName("clientresponse." + "ResponseBoardQuestion"));
        } catch (ClassNotFoundException ex) {
            ac.log("Class Not Found Exception in class ResponseFromServerTable in method init()");
        }
    }

    public static ResponseFromServer get(short response_id) {
        ResponseFromServer response = null;

        try {
            Class name = responseTable.get(response_id);

            if (name != null) {
                response = (ResponseFromServer) name.newInstance();
            } else {
                System.out.println("Invalid Response Code: " + response_id);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return response;
    }
}
